let http = require("http");
let https = require("https");

let server = http.createServer();
server.on("request", (req, res) => {
  res.end("111");

  //获得了一段html代码，虽然不知道用途，但至少证明POST请求成功了
  httpsPost((data) => {
    console.log(data);
  });
});
server.listen(3000, () => {
  console.log("3000 port");
});

function httpsPost(callback) {
  let data = "";

  // 设置传入参数
  let options = {
    hostname: "data.bilibili.com",
    port: "443",
    pathname: "/gol/postweb?013324",
    method: "POST",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
  };

  //   创建一个请求
  let req = https.request(options, (res) => {
    res.on("data", (chunk) => {
      data += chunk;
    });
    // 结束之后回调
    res.on("end", () => {
      callback(data);
    });
  });

  req.write(
    `0133241684285583006https%3A%2F%2Fwww.bilibili.com%2F|333.1007.main.home-page.DATA.browser-zoom||1684285583006|||1280x210|1|{"flink":1,"dpi":1.5,"widthRatio":1,"isMac":"win","lsid":"2AFDC6105_1882735A325","b_nut_h":1680512400,"buvid_fp":"d6e0bfe1797136fbd310394d311049a1","buvid4":"2E06B82E-8BC7-72A7-B594-A653DFD6ED8864651-023040317-DZxvlWDvNxFOBheTQltEkw==","bsource":null,"uaSource":null}|{"b_ut":"5","home_version":"V_TOPSWITCH_FLEX","i-wanna-go-back":"-1","in_new_ab":true,"ab_version":{"for_ai_home_version":"V_TOPSWITCH_FLEX","tianma_banner_inline":"CONTROL","login_dialog_version":"V0","h5_read_awaken_app":"B","home_pop_window":"V1","channel_show_back_btn":"HIDDEN","nano_pcdn_version":"V_PCDN","in_theme_version":"CLOSE","storage_back_btn":"HIDE","web_homepage_video_continuation":"CLOSE","clean_version_old":"KEEP"},"ab_split_num":{"for_ai_home_version":186,"tianma_banner_inline":186,"login_dialog_version":94,"h5_read_awaken_app":19,"home_pop_window":97,"channel_show_back_btn":18,"nano_pcdn_version":76,"in_theme_version":36,"storage_back_btn":75,"web_homepage_video_continuation":72,"clean_version_old":26}}||27988E94-E4DF-10B81-278F-F47C4EE3AEE363796infoc|zh-CN||1`
  );
  req.end();
}

// POST请求预设
// 1.创建请求req = https.request()
// 2.写入POST数据流,req.write,req.end
// 3.创建配置对象，确定POST信息